/**
 * The Prophecy
 * java based lightweight texas hold'em poker software base
 * http://code.google.com/p/theprophecy/
 */

package org.poker.prophecy.core;

import java.util.Vector;

import junit.framework.TestCase;

/**
 * @author bg
 */

public class PokerHandComparerTest extends TestCase {

    public void testCompareFullHouses(){
        
    }
    
    
    public PokerHandComparerTest(String name) {
        super(name);
        //displayConparableHands();
        for (int i = 0; i < 100; i++) {
            System.out.println("********************************************************");
            System.out.println("Spiel Nr. "+i+")");
            System.out.println("********************************************************");
            displayHoldEmGame();
        }
    }

    public static void displayHoldEmGame(){
        CardDeck deck = null;
        Vector<Card> flop = new Vector<Card>();
        Card turn = null;
        Card river = null;
        deck = new CardDeck();
        deck.shuffleDeck();
        flop.addElement(deck.getCardsInDeck().elementAt(0));
        flop.addElement(deck.getCardsInDeck().elementAt(1));
        flop.addElement(deck.getCardsInDeck().elementAt(2));
        turn = deck.getCardsInDeck().elementAt(3);
        river = deck.getCardsInDeck().elementAt(4);
        Vector<Card> p1pocket = new Vector<Card>();
        p1pocket.addElement(deck.getCardsInDeck().elementAt(5));
        p1pocket.addElement(deck.getCardsInDeck().elementAt(6));
        Vector<Card> p2pocket = new Vector<Card>();
        p2pocket.addElement(deck.getCardsInDeck().elementAt(7));
        p2pocket.addElement(deck.getCardsInDeck().elementAt(8));
        Vector<Card> p3pocket = new Vector<Card>();
        p3pocket.addElement(deck.getCardsInDeck().elementAt(9));
        p3pocket.addElement(deck.getCardsInDeck().elementAt(10));
        Vector<Card> p4pocket = new Vector<Card>();
        p4pocket.addElement(deck.getCardsInDeck().elementAt(11));
        p4pocket.addElement(deck.getCardsInDeck().elementAt(12));
        
        Vector<Card> p1Seven = new Vector<Card>();
        p1Seven.addElement(p1pocket.elementAt(0));
        p1Seven.addElement(p1pocket.elementAt(1));
        p1Seven.addAll(flop);
        p1Seven.add(river);
        p1Seven.add(turn);
        PokerHand p1Hand = CardVectorTools.getBestHandFromSevenCardsVector(p1Seven);
        
        Vector<Card> p2Seven = new Vector<Card>();
        p2Seven.addElement(p2pocket.elementAt(0));
        p2Seven.addElement(p2pocket.elementAt(1));
        p2Seven.addAll(flop);
        p2Seven.add(river);
        p2Seven.add(turn);
        PokerHand p2Hand = CardVectorTools.getBestHandFromSevenCardsVector(p2Seven);
        
        Vector<Card> p3Seven = new Vector<Card>();
        p3Seven.addElement(p3pocket.elementAt(0));
        p3Seven.addElement(p3pocket.elementAt(1));
        p3Seven.addAll(flop);
        p3Seven.add(river);
        p3Seven.add(turn);
        PokerHand p3Hand = CardVectorTools.getBestHandFromSevenCardsVector(p3Seven);

        Vector<Card> p4Seven = new Vector<Card>();
        p4Seven.addElement(p4pocket.elementAt(0));
        p4Seven.addElement(p4pocket.elementAt(1));
        p4Seven.addAll(flop);
        p4Seven.add(river);
        p4Seven.add(turn);
        PokerHand p4Hand = CardVectorTools.getBestHandFromSevenCardsVector(p4Seven);
        
        Vector<PokerHand> sieger = new Vector<PokerHand>();
        if (PokerHandComparer.compare(p1Hand, p2Hand) == 0){
            sieger.addElement(p1Hand);
        }
        else{
            if (PokerHandComparer.compare(p1Hand, p2Hand) == 1){
                sieger.addElement(p2Hand);
            }
            else{
                sieger.addElement(p1Hand);
                sieger.addElement(p2Hand);
            }
        }
        if (PokerHandComparer.compare(sieger.elementAt(0), p3Hand) == 0){
            //NOOP
        }
        else{
            if (PokerHandComparer.compare(sieger.elementAt(0), p3Hand) == 1){
                sieger.removeAllElements();
                sieger.addElement(p3Hand);
            }
            else{
                sieger.addElement(p3Hand);
            }
        }
        if (PokerHandComparer.compare(sieger.elementAt(0), p4Hand) == 0){
            //NOOP
        }
        else{
            if (PokerHandComparer.compare(sieger.elementAt(0), p4Hand) == 1){
                sieger.removeAllElements();
                sieger.addElement(p4Hand);
            }
            else{
                sieger.addElement(p4Hand);
            }
        }
        
        System.out.println("Flop ist "+flop+", Turn ist "+turn+", River ist "+river);
        System.out.println("P1-Pocket: "+p1pocket+" mit Hand "+p1Hand+" ("+p1Hand.getHandRankAsPrintableString()+")");
        System.out.println("P2-Pocket: "+p2pocket+" mit Hand "+p2Hand+" ("+p2Hand.getHandRankAsPrintableString()+")");
        System.out.println("P3-Pocket: "+p3pocket+" mit Hand "+p3Hand+" ("+p3Hand.getHandRankAsPrintableString()+")");
        System.out.println("P4-Pocket: "+p4pocket+" mit Hand "+p4Hand+" ("+p4Hand.getHandRankAsPrintableString()+")");
        System.out.println("Es gibt "+sieger.size()+" Sieger mit "+sieger.elementAt(0).getHandRankAsPrintableString());
        System.out.println("********************************************************");
      
        
    }
    
    public static void displayConparableHands(){
        CardDeck deck = null;
        PokerHand ph0 = null;
        PokerHand ph1 = null;
        for (int i = 0; i < 200; i++) {
            deck = new CardDeck();
            deck.shuffleDeck();
            ph0 = new PokerHand(deck.getCardsInDeck().elementAt(0),deck.getCardsInDeck().elementAt(1),deck.getCardsInDeck().elementAt(2),deck.getCardsInDeck().elementAt(3),deck.getCardsInDeck().elementAt(4));
            ph1 = new PokerHand(deck.getCardsInDeck().elementAt(5),deck.getCardsInDeck().elementAt(6),deck.getCardsInDeck().elementAt(7),deck.getCardsInDeck().elementAt(8),deck.getCardsInDeck().elementAt(9));
            
            System.out.println("********************************************************");
            System.out.println("Hand 0: "+ph0+" ist "+ph0.getHandRankAsPrintableString());
            System.out.println("Hand 1: "+ph1+" ist "+ph1.getHandRankAsPrintableString());
            System.out.println("Winner ist "+PokerHandComparer.compare(ph0, ph1));
        }
    }
    
    public static void main(String[] args) {
        junit.textui.TestRunner.run(PokerHandComparerTest.class);
    }
    
    protected void setUp() throws Exception {
        super.setUp();
    }

    protected void tearDown() throws Exception {
        super.tearDown();
    }

}
